package com.xmall.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmall.auth.dao.SysPermissionMapper;
import com.xmall.auth.entity.SysPermission;
import com.xmall.auth.service.ISysPermissionService;
import com.xmall.common.config.PlatformContant;
import com.xmall.common.config.PojoUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 后台用户权限表 服务实现类
 * </p>
 *
 * @author liuzh
 * @since 2020-06-14
 */
@Service
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements ISysPermissionService {
    @Autowired
    SysPermissionMapper sysPermissionMapper;

    @Override
    public boolean saveSysPermission(SysPermission sysPermission) {
        PojoUtils.setSysProperties(sysPermission, PlatformContant.OpType.insert);
        return save(sysPermission);
    }

    @Override
    public boolean updateSysPermission(Long id, SysPermission sysPermission) {
        SysPermission oldSysPermission = getById(id);
        BeanUtils.copyProperties(sysPermission, oldSysPermission);
        PojoUtils.setSysProperties(oldSysPermission, PlatformContant.OpType.update);
        boolean update = update(
                oldSysPermission,
                new QueryWrapper<SysPermission>()
                        .lambda().eq(SysPermission::getId, id)
        );
        return update;
    }

    @Override
    public boolean deleteSysPermission(Long id) {
        boolean b = removeById(id);
        return b;
    }

    @Override
    public SysPermission getSysPermission(Long id) {
        SysPermission sysPermission = getById(id);
        return sysPermission;
    }
}
